window.index = 0;
var elementById = document.getElementById("serial_number");
var serial_number_arr = [];
elementById.addEventListener("keydown", function (e) {

  var category = JSON.parse(localStorage.getItem("Conditions_category"))
  var typical = JSON.parse(localStorage.getItem("Conditions_typical"))
  var brand = JSON.parse(localStorage.getItem("Conditions_brand"))
  var model = JSON.parse(localStorage.getItem("Conditions_model"))

  var category_class = document.getElementById("category")
  var typical_class = document.getElementById("typical")
  var brand_class = document.getElementById("brand")
  var model_class = document.getElementById("model")


  var text = elementById.value;
  if (e.keyCode == 13 && text != "" && text != undefined && text != null) {

    window.index++;
    serial_number_arr.push(text);
    // console.log(serial_number_arr);
    
    localStorage.setItem("serial_number_arr", JSON.stringify(serial_number_arr));
    let html =
      '<td> ' + text + ' </td>  <' +
      'td > ' + category.category + ' </td>  <' +
      'td > ' + typical.typical + ' </td> <' +
      'td > ' + brand.brand + ' </td> <' +
      'td > ' + model.model + ' </td>' +
      '<td class = ""' +
      'style = "display: flex;justify-content: space-around;" >' +
      '<a title = "删除"' +
      'onclick = \" DeleteItem(this, ' +text+')\"' +
      'href = "javascript:;" >' +
      '<button class = "layui-btn layui-btn-danger layui-btn-mini"' +
      'onclick = ""> <i class = "layui-icon" > </i>删除</button>' +
      '</a> ' +
      '</td> '

    $('#table-thd').removeClass('layui-hide');
    var the_tr = document.createElement("tr");
    the_tr.innerHTML = html;
    document.getElementById("table-tby").appendChild(the_tr);
    elementById.value = "";
  }
});

